
# 滑动窗口中的最大值

from collections import deque

class Solution:

    def maxSlidingWindow(self, nums, k):
        if not nums or k == 0:
            return []
        q = deque()
        # 初始化第一个窗口
        res = []
        for i in range(k):
            # 非递增
            while q and q[-1] < nums[i]:
                q.pop()

            q.append(nums[i])
        
        res.append(q[0])

        for i in range(k, len(nums)):

            if q[0] == nums[i - k]:
                q.popleft()

            while q and q[-1] < nums[i]:
                q.pop()
            
            q.append(nums[i])
            res.append(q[0])

        return res




